package com.magicode.cms.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import com.magicode.cms.common.assist.bean.VideoPramsInfos;
import com.magicode.cms.entiy.base.VideoPrams;
import com.magicode.cms.entiy.base.VideoProgram;
import com.magicode.cms.service.IVideoPramsService;
import com.magicode.common.dao.ICommonDaoService;

public class VideoPramsServiceImpl implements IVideoPramsService{

	@Override
	public void addSelName(String videoPrams_id,String videoPrams_abc_id) {
		this.deleteVideoPramsByCode(videoPrams_abc_id);
		VideoPramsInfos vpinfos = new VideoPramsInfos(videoPrams_abc_id);	
		vpinfos = this.refreshVideoProgramTitles(videoPrams_id, vpinfos);
	}
	
	
	public VideoPramsInfos  refreshVideoProgramAbcs(String videoPrams_abc_id,VideoPramsInfos vpinfos){
		String hql="select new Map(t.initialWordDic.id as id,t.initialWordDic.title as title) from " +VideoProgram.class.getName()+" t left outer join fetch t.initialWordDic  where t.initialWordDic.id='"+videoPrams_abc_id+"' ";
		 try {
		List<Map<String,Object>> prams=	commonDaoService.queryList(hql, null);
		vpinfos.setAbcs(prams);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return vpinfos;
	}
	
	public VideoPramsInfos  refreshVideoProgramTitles(String videoPrams_id,VideoPramsInfos vpinfos){
		String hql="select new Map(t.id as id,t.title as title) from " +VideoProgram.class.getName()+" t where t.id='"+videoPrams_id+"' ";
		 try {
		List<Map<String,Object>> prams=	commonDaoService.queryList(hql, null);
		vpinfos.setNames(prams);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return vpinfos;
	}
	public void deleteVideoPramsByCode(String id){
		Object obj = commonDaoService.get(VideoPrams.class, id);
		if(null!=obj){
			commonDaoService.delete(obj);
		}
	}
	
	@Autowired
	@Qualifier("commonDaoService")
	private ICommonDaoService commonDaoService;
	public ICommonDaoService getCommonDaoService() {
		return commonDaoService;
	}
	public void setCommonDaoService(ICommonDaoService commonDaoService) {
		this.commonDaoService = commonDaoService;
	}
	
	
}
